<?php
namespace Modules\Admin\Controllers;

class AuthController extends \Phalcon\Mvc\Controller {
  public function loginAction() {
    $loginUserValidation = (new \Modules\Admin\Validations\AdminValidation()) -> login($this -> request -> getPost());
    if($loginUserValidation['code'] != 0) {
      return $this -> response -> setJsonContent($loginUserValidation);
    }
    
    $authorizeAdminService = (new \Modules\Admin\Services\AdminService()) -> authorize($loginUserValidation['data']['admin']);
    if($authorizeAdminService['code'] != 0) {
      return $this -> response -> setJsonContent($authorizeAdminService);
    }

    return $this -> response -> setJsonContent([
      'code' => 0,
      'message' => '授权成功!',
      'token' => $authorizeAdminService['token'],
      'data' => [
        'admin' => $authorizeAdminService['data']['admin'],
        'config' => $this -> config
      ]
    ]);
  }
}
?>